The technology described herein relates to graphics processing and in particular to the operation of graphics processing systems that include a vertex shading stage.
As is known in the art, graphics processing is typically carried out in a pipelined fashion, with one or more pipeline stages operating on the data to generate the final image that is displayed. Two important stages of this process typically are so-called vertex shading operations such as transformations and lighting that are carried out on the vertices of primitives (polygons) representing the image to be displayed, and the subsequent fragment (pixel) shading operations that shade (colour) the individual fragments (pixels) that make up the image to be displayed.
The vertex shading operations, such as vertex transformations and lighting, are typically carried out in a so-called “vertex shader” stage of the graphics process. This is typically a programmable processing unit that executes vertex shader programs on input data values to generate a desired set of output data (e.g. appropriately transformed and lit vertex data) for processing by the rest of the graphics pipeline. (As is known in the art, each primitive (polygon) of a scene is usually defined and represented as a set of vertices, with each vertex having associated with it a set of data values for the vertex. The vertex shading process modifies the initially defined data values for a vertex, e.g. based on any transformations or lighting that the primitive that the vertex relates to is to be subjected to.)
Once the input data values for a scene have been vertex “shaded”, the primitives representing the scene are then usually rasterised to generate a plurality of “fragments” to be processed for the scene. (As is known in the art, “fragments” are the discrete graphical entities on which the graphics processing operations (such as rendering) are carried out. Each fragment will correspond to a sampling point or sampling points of the scene and have associated with it the necessary data, such as red, green, blue (RGB) colour values, an alpha (transparency) value, and a depth value, to allow the sample point(s) to be displayed. (Fragments may also be referred to as pixels, although it is not inevitably the case that a given fragment will correspond exactly to a single pixel (pixel element) in the final display, as post-processing, such as down-scaling, may mean that there is not a one-to-one correspondence between the entities (fragments) that the graphics processing operates on and the display pixels.))
The graphics fragments, once generated, undergo a number of processes to shade them to generate their final output colour, etc., values, such as applying textures, blending, etc. Such processes to derive the output data values, etc., e.g. necessary to display the sample point(s) that the fragments represent, may be referred to as “fragment shading” or “pixel shading” and are carried out in a fragment shading (also called a pixel shading) stage of the processing pipeline. The fragment shading process processes the initially defined fragment data values for a fragment to derive the output data for the fragment (data needed to display the sample point(s) that the fragment represents) correctly. The fragment shader again may be a programmable unit that executes one or more fragment shader programs to shade (colour) the fragments appropriately.
The vertex and fragment shading operations normally operate, as is known in the art, on so-called “attributes”. An attribute is an input or output variable in a shader program and may represent for example, a position, colour, or texture coordinate, etc.
The input attributes to the vertex shader may be referred to as primary attributes, and the output attributes of the vertex shader (which will also be the fragment shader input attributes) may be referred to as secondary attributes. There will normally be a fixed number of primary attributes (vertex shader input variables) and a fixed number of secondary attributes (vertex shader output/fragment shader input variables) for a given shader program (linked vertex and fragment shader).
For a particular draw call, for non-instanced drawing each primary attribute (vertex shader input variable) will have a defined value for each vertex of the draw call. In the case of instanced drawing, each primary attribute (vertex shader input variable) will have a defined value either for each vertex, or for each instance. Thus, in instanced mode operation, some primary attributes will have values that are defined on a per-vertex basis, and so may be thought of as “per-vertex” attributes. Equally, there may be primary attributes whose values are defined on a per-instance basis, which may accordingly be thought of as “per-instance” attributes.
As is known in the art, when a graphics processor is operating in so-called “instanced” mode, multiple “instances” of the same input geometry will be drawn (e.g. in a slightly different position each time). In this case, the vertex shader will be run once per vertex per instance (i.e. a number of times equal to the number of vertices times the number of instances), rather than just once per vertex. Thus there will normally be a vertex shader output (a secondary attribute value) generated for each secondary attribute (vertex shader output variable) for each different vertex and instance combination.
The primary attribute values are typically stored in memory for use by the vertex shader. (This is normally specified in the graphics API.) The application on the host system that requires the graphics processing will normally specify the memory layout of the vertex shader input attributes and the input attribute values.
To provide the output, vertex shaded, secondary attribute values to the subsequent processing stages, such as the fragment shader, in the case of traditional, immediate mode graphics processing units, the vertex shader outputs are typically channelled through internal pipelines inside the chip. In the case of deferred rendering graphics processors (such as tile-based graphics processors), the vertex shader outputs (vertex-shaded attribute values) are usually written to memory, from where they are then accessed as needed by the fragment shader, etc.
Where the attribute values are stored in memory, the vertex shader and fragment shader, etc., will normally be provided with and use appropriate memory addresses to store and retrieve the appropriate attribute values from the memory where those values are to be or are stored.
For example, a vertex shader will execute an instruction to load a particular input attribute value for processing, and that instruction will include or indicate a memory address to allow the vertex shader to retrieve the appropriate attribute value from memory where the input attribute values are stored. Similarly, a fragment shader will execute an instruction to load a particular vertex-shaded output attribute value for processing, and that instruction will include or indicate memory address(es) to allow the fragment shader to retrieve the appropriate output attribute values for each corner vertex of the polygon (primitive) in question from memory where the output attribute values (the outputs of the vertex shader) are stored.
The Applicants believe that there remains scope for improvements to the operation of graphics processors that include vertex shading stages.